package com.yb.nowcoder;

import java.util.Scanner;

/**
 * 华为机试练习第5题
 */
public class Main15 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNextLine()) {
            String s = in.nextLine();
            if (s.length() <= 8 || !typeCheck(s) || !subCheck(s)) {
                System.out.println("NG");
            } else {
                System.out.println("OK");
            }
        }
    }

    public static boolean typeCheck(String str) {
        int count = 0;
        char[] arr = str.toCharArray();
        for (char c : arr) {
            if (c >= 'a' && c <= 'z') {
                count++;
                break;
            }
        }
        for (char c : arr) {
            if (c >= 'A' && c <= 'Z') {
                count++;
                break;
            }
        }
        for (char c : arr) {
            if (c >= '0' && c <= '9') {
                count++;
                break;
            }
        }
        for (char c : arr) {
            if (!(c >= '0' && c <= '9') && !(c >= 'A' && c <= 'Z') && !(c >= 'a' && c <= 'z')) {
                count++;
                break;
            }
        }
        return count >= 3;
    }

    public static boolean subCheck(String str) {
        //字符串长度已经确定大于8
        while (str.length() > 2) {
            String sub = str.substring(0, 3);
            String other = str.substring(3);
            if (other.length() < 3) {
                return true;
            }
            if (other.contains(sub)) {
                return false;
            }
            str = str.substring(1);
        }
        return true;
    }
}
